package com.imooc.miaosha.service;

import com.imooc.miaosha.dao.UserDao;
import com.imooc.miaosha.domain.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author liyuhui
 */
@Service
public class UserService {

   @Autowired
   UserDao userDao;

    public User getById(int id) {
        return userDao.getById(id);
    }

    @Transactional(rollbackFor = Exception.class)
    public boolean tx() {
        User u2= new User();
        u2.setId(2);
        u2.setName("2222");
        userDao.insert(u2);

        //插入冲突
        User u3= new User();
        u3.setId(1);
        u3.setName("11111");
        userDao.insert(u3);

        return true;
    }
}
